package logic.gridNodes;

import eduni.simjava.Sim_entity;
import java.util.LinkedList;
import logic.distributions.AbstractGenerator;
import logic.distributions.ConstantGenerator;
import logic.distributions.UniformGenerator;
import logic.gridSimInterface.SimTags;
import logic.gridSimInterface.user.UserGenerationParameters;
import logic.gridSimInterface.user.UserSimple;
import logic.topology.NetworkNode;

/**
 * Uzivatel moze byt spojeny iba s jednym routerom (globalnym alebo lokalnym)
 */
public class GridUser extends NetworkNode {

    private UserGenerationParameters gp;
    
    private static int count = 0;
    
    private static final String _obmedzenie = 
            "User can be connected only to one router!";
    
    public GridUser() throws Exception {
        super("GridUserDefault123456789xtea",0,0);
        count++;
        setName("User" + count);
        gp = new UserGenerationParameters();
    }

    /**
     * <font face="">vracia null, ak je mozne vytvorit novu linku z daneho uzla
     * (este 
     *    sa nevie, aky bude koniec linky). Inak vracia dovod, preco sa nemoze 
     *    vytvorit
     * </font>
     */
    public String canCreateNewLink() {
        if (getLinks().size() == 0)
            return null;
        else
            return new String(_obmedzenie);
    }

    /**
     * Vracia null, ak moze vytvorit spojenie s danym elementom. Inak vracia
     * dovod, 
     *    preco nie. Kontroluje aj, ci uz linka s danym elementom neexistuje.
     */
    public String canCreateNewLink(NetworkNode end) {
        if (getLinks().size() > 0)
            return new String(_obmedzenie);
        
        if ((end instanceof GridRouterLocal) || (end instanceof GridRouterGlobal))
            return null;
        
        return new String(_obmedzenie);
    }
    
    public LinkedList<Sim_entity> createGridSimEntities(String globalBrokerName, boolean trace_flag) throws Exception {
        LinkedList<Sim_entity> result = new LinkedList<Sim_entity>();
        result.add( new UserSimple(
                        getName(),
                        getLinks().iterator().next().createSimpleLink(),
                        globalBrokerName,
                        gp
                        )
                 );
        return result;
    }

    public String getOs() {
        return gp.os;
    }

    public void setOs(String os) {
        this.gp.os = os;
    }

    public String getArchitecture() {
        return gp.architecture;
    }

    public void setArchitecture(String architecture) {
        this.gp.architecture = architecture;
    }

    public int getTasksCount() {
        return gp.tasksCount;
    }

    public void setTasksCount(int tasksCount) {
        this.gp.tasksCount = tasksCount;
    }

    public AbstractGenerator getTaskLength() {
        return gp.taskLength;
    }

    public void setTaskLength(AbstractGenerator taskLength) {
        this.gp.taskLength = taskLength;
    }

    public AbstractGenerator getFileSize() {
        return gp.fileSize;
    }

    public void setFileSize(AbstractGenerator fileSize) {
        this.gp.fileSize = fileSize;
    }

    public AbstractGenerator getOutputSize() {
        return gp.outputSize;
    }

    public void setOutputSize(AbstractGenerator outputSize) {
        this.gp.outputSize = outputSize;
    }

    public int getGridletType() {
        return gp.gridletType;
    }

    public void setGridletType(int gridletType) {
        this.gp.gridletType = gridletType;
    }

    public AbstractGenerator getStartTime() {
        return gp.startTime;
    }

    public void setStartTime(AbstractGenerator startTime) {
        this.gp.startTime = startTime;
    }

    public int getWorkflow() {
        return gp.workflow;
    }

    public void setWorkflow(int workflow) {
        this.gp.workflow = workflow;
    }
}
